package com.test.design.pattern.combination;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClasName Menu
 * @Descripution TODO
 * @Author leikw
 * @Date 2021/12/18 11:32
 * @Version V1.0
 */
public class Menu extends MenuComponent {

    public List<MenuComponent> menuComponentList = new ArrayList<MenuComponent>();

    public Menu(String name , int level) {
        this.name =name;
        this.level =level;
    }

    @Override
    public void add(MenuComponent menuComponent) {
        menuComponentList.add(menuComponent);
    }

    @Override
    public void remove(MenuComponent menuComponent) {
        menuComponentList.remove(menuComponent);
    }

    @Override
    public MenuComponent getChild(int index) {
        return menuComponentList.get(index);
    }

    public void print() {
        //打印菜单名称
        for(int i = 0; i < level; i++) {
            System.out.print("--");
        }

        System.out.println(name);

        //打印子菜单或者子菜单项名称
        for (MenuComponent component : menuComponentList) {
            component.print();
        }
    }


}
